package vn.com.pavibook.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import vn.com.pavibook.dao.BookDao;
import vn.com.pavibook.dao.BookTypeDao;
import vn.com.pavibook.dao.PublisherDao;
import vn.com.pavibook.domain.model.Book;
import vn.com.pavibook.domain.model.BookType;
import vn.com.pavibook.domain.model.PagingInfo;
import vn.com.pavibook.domain.model.Publisher;
import vn.com.pavibook.domain.model.SearchResult;

@Service
public class BooksOnlineService {
	@Autowired
	private BookTypeDao bookTypeDao;
	@Autowired
	private BookDao bookDao;
	@Autowired
	private PublisherDao publisherDao;
	
	public List<BookType> getAllBookType(){
		return bookTypeDao.getAllBookType();
	}
	
	public List<Book> getListBooKByCategory(String bookType){
		return bookDao.getTop10BookByCategory(bookType); 
	}
	
	public Book getBookById(int id){
		return bookDao.getBookById(id);
	}
	
	public BookType getCategoryById(int id){
		return bookTypeDao.getBookTypeById(id);
	}
	
	public Publisher getPublisherByid(int id){
		SearchResult<Publisher> result = publisherDao.getPersonalInfoById(id);
		if(result.getSearchResult().size() == 0) return null;
		return result.getSearchResult().get(0);
	}
	
	public List<Book> getRelatedBook(int categoryId, int id){
		List<Book> listBook = new ArrayList<Book>();
		listBook = bookDao.getRelatedBook(categoryId, id).getSearchResult();
		return listBook;
	}
	
	public SearchResult<Book> getBooksByBookTypeId(PagingInfo pagingInfo, int id){
		return bookDao.getBooksByBookTypeId(pagingInfo, id);
	}
	
	public SearchResult<Book> getBooksBykeyword(PagingInfo pagingInfo, String keyword){
		return bookDao.getBooksBykeyword(pagingInfo, keyword);
	}
	
	
}
